<?php
$themename = "Initial";
$version = " 0.9 免费版";
$sn = "ini";
$options = array (array("name"=>$themename." Options"),

//SEO设置
array("name"=>"网站SEO设置","type"=>"section"),

array("type"=>"open"),
array("name"=>"描述（Description）",
"id"=>$sn."_description",
"type"=>"textarea",
"std"=>"输入您的网站描述, 一般不超过200个字符"),

array("name"=>"关键词（KeyWords）",
"id"=>$sn."_keywords",
"type"=>"textarea",
"std"=>"输入您的网站关键字, 一般不超过100个字符"),
array("type"=>"close"),

//站点信息设置
array("name"=>"站点信息设置","type"=>"section"),

array("type"=>"open"),
array("name"=>"订阅地址",
"desc"=>"导航栏里的订阅按钮, 留空则使用RSS2订阅",
"id"=>$sn."_rss",
"type"=>"text"),

array("name"=>"新浪微博",
"desc"=>"导航栏里的新浪微博地址, 留空则不显示微博图标",
"id"=>$sn."_weibo",
"type"=>"text"),

array("name"=>"邮箱地址",
"desc"=>"导航栏里的收件邮箱, 默认使用管理员邮箱",
"id"=>$sn."_mail",
"type"=>"text"),

array("name"=>"Google+ ID",
"desc"=>"显示主站谷歌搜索结果中的作者信息, 可到 <a href='https://www.google.com.hk/webmasters/tools/richsnippets' target='_blank'>这里</a> 测试, 其他作者请到 <a href='".get_bloginfo(url)."/wp-admin/profile.php' target='_blank'>个人资料</a> 填写信息",
"id"=>$sn."_ggplus",
"type"=>"text"),

array("name"=>"您的备案号",
"desc"=>"如有备案号, 直接输入即可在footer中显示, 留空则不显示",
"id"=>$sn."_beian",
"type"=>"text"),

array("name"=>"评论提示",
"desc"=>"评论为空时的提示语",
"id"=>$sn."_cmtinfo",
"type"=>"text",
"std"=>"沙发, 我的最爱！"),
array("type"=>"close"),

//页面模块设置
array("name"=>"页面模块设置","type"=>"section"),

array("type"=>"open"),
array("name"=>"首页幻灯片",
"desc"=>"首页顶部幻灯片展示文章的数量, 不要超过10篇, 建议6篇",
"id"=>$sn."_num",
"type"=>"text",
"std"=>"6"),

array("name"=>"文章摘要",
"desc"=>"在文章顶部显示文章摘要 | <span style='color:red'>默认不显示</span>",
"id"=>$sn."_excerpt",
"type"=>"select",
"options"=>array('Hide','Display')),

array("name"=>"媒体分享",
"desc"=>"主题集成不同分类的展示页面, 若你有分享音乐或视频的爱好, 可开启此功能 | <span style='color:red'>默认关闭</span>",
"id"=>$sn."_media",
"type"=>"checkbox"),

array("name"=>"媒体分类ID",
"desc"=>"输入需要单独展示的多媒体分类ID, 免费版仅支持一个ID且不支持子分类",
"id"=>$sn."_media_id",
"in"=>$sn."_media_child",
"type"=>"text"),

array("name"=>"版权信息",
"desc"=>"在文章页面显示版权信息 | <span style='color:red'>默认显示</span>",
"id"=>$sn."_copyright",
"type"=>"select",
"options"=>array("Display", "Hide")),

array("name"=>"作者信息",
"desc"=>"在文章页面显示作者信息, 请到 <a href='".get_bloginfo(url)."/wp-admin/profile.php' target='_blank'>个人资料</a> 填写, 个人说明简短为好 | <span style='color:red'>默认不显示</span>",
"id"=>$sn."_author",
"type"=>"select",
"options"=>array("Hide", "Display")),

array("name"=>"相关文章",
"desc"=>"在文章下方显示相关文章, 可能会与类似插件有冲突 | <span style='color:red'>默认关闭</span>",
"id"=>$sn."_post",
"type"=>"checkbox",),

array("name"=>"相关文章数目",
"desc"=>"建议7或14, 文章通过相同分类和标签获取, 不足则显示随机文章",
"id"=>$sn."_postnum",
"type"=>"text",
"in"=>$sn."_post_child",
"std"=>"7"),

array("name"=>"首页侧边栏悬停模块",
"desc"=>"此设置首页有效, 当侧边栏滚动结束时小工具悬停在页面, 更改小工具序号（数字）即可, 最多设置三个, 若关闭全部改成999 | <span style='color:red'>默认显示前两个</span>",
"id"=>$sn."_roller_home",
"type"=>"text",
"std"=>"c = 1 ,d = 2 ,e = 999 ;"),

array("name"=>"侧边栏悬停模块",
"desc"=>"其他页面悬停的小工具序号, 设置同上 | <span style='color:red'>默认显示前两个</span>",
"id"=>$sn."_roller",
"type"=>"text",
"std"=>"c = 1 ,d = 2 ,e = 999 ;"),
array("type"=>"close"),

//功能模块设置
array("name"=>"功能模块设置","type"=>"section"),

array("type"=>"open"),
array("name"=>"搜索按钮",
"desc"=>"导航栏的搜索按钮, <span style='color:red'>默认隐藏侧边栏时自动显示</span>, 选择是否一直显示",
"id"=>$sn."_search",
"type"=>"select",
"options"=>array("Hide", "Display")),

array("name"=>"评论头像",
"desc"=>"评论中是否显示头像 | <span style='color:red'>默认显示</span>",
"id"=>$sn."_type",
"type"=>"select",
"options"=>array("Display", "Hide")),

array("name"=>"头像缓存",
"desc"=>"缓存评论头像到本地, 需要在根目录建立avatar文件夹, 并且还要有默认头像avatar.jpg | <span style='color:red'>默认关闭</span>",
"id"=>$sn."_avatar",
"type"=>"checkbox"),

array("name"=>"百度分享按钮",
"desc"=>"开启百度分享按钮, 显示在文章下方, 同时页面右侧出现导航按钮 | <span style='color:red'>默认关闭</span>",
"id"=>$sn."_bdshare",
"type"=>"checkbox"),

array("name"=>"百度分享@微博昵称",
"desc"=>"读者分享文章时@的对象, 如：<strong>@柳飘清枫</strong>, 留空则显示：<strong>来自→".get_bloginfo(name)."</strong>",
"id"=>$sn."_uid",
"in"=>$sn."_bdshare_child",
"type"=>"text"),

array("name"=>"百度分享开放平台",
"desc"=>"百度分享默认使用自身appkey分享到各大平台, 您也可以自定义您所有的appkey来进行分享, 仅支持新浪和腾讯开放平台, 无则不选",
"id"=>$sn."_sns",
"in"=>$sn."_bdshare_child",
"type"=>"select",
"options"=>array("","tsina", "tqq")),

array("name"=>"开放平台appkey",
"id"=>$sn."_appkey",
"in"=>$sn."_bdshare_child",
"type"=>"text"),

array("name"=>"评论编辑器",
"desc"=>"开启评论框编辑器, 方便输入图片、链接等 | <span style='color:red'>默认开启</span>",
"id"=>$sn."_editor",
"type"=>"checkbox",
"std"=>"true"),

array("name"=>"Fancybox",
"desc"=>"使用 Fancybox 预览图片, 开启后给文章图片添加链接即可 | <span style='color:red'>默认关闭</span>",
"id"=>$sn."_fancybox",
"type"=>"checkbox"),

array("name"=>"代码高亮",
"desc"=>"轻量级 prettify 代码高亮, 使用时在HTML编辑器里输入[code]代码[/code], 或使用编辑器按钮快捷输入 | <span style='color:red'>默认关闭</span>",
"id"=>$sn."_prettify",
"type"=>"checkbox"),

array("name"=>"管理站点",
"desc"=>"开启管理站点工具栏, 带登录注册按钮, 同时关闭WordPress工具条; 若未开启公告栏与面包屑导航合并显示 | <span style='color:red'>默认关闭</span>",
"id"=>$sn."_admin",
"type"=>"checkbox"),

array("name"=>"公告栏",
"desc"=>"在页面底部显示公告栏, 若未设置自定义代码将同时开启撰写公告功能, 若同时开启管理站点则合并显示 | <span style='color:red'>默认关闭</span>",
"id"=>$sn."_bulletin",
"type"=>"checkbox",),
array("type"=>"close"),

//网站统计
array("name"=>"网站统计设置","type"=>"section"),

array("type"=>"open"),
array("name"=>"百度统计",
"desc"=>"启用百度统计来分析网站数据, 需要输入您的跟踪ID才能正确安装",
"id"=>$sn."_bdtj",
"type"=>"checkbox"),

array("name"=>"百度统计跟踪ID",
"id"=>$sn."_bdtjcode",
"in"=>$sn."_bdtj_child",
"type"=>"text",
"std"=>"example: 6F368b998d5fc627c7dd92063108cf49ee"),

array("name"=>"谷歌统计",
"desc"=>"启用谷歌统计来分析网站数据, 需要输入您的跟踪ID以及域名才能正确安装",
"id"=>$sn."_ggtj",
"type"=>"checkbox"),

array("name"=>"谷歌统计跟踪ID",
"id"=>$sn."_ggtjcode",
"in"=>$sn."_ggtj_child",
"type"=>"text",
"std"=>"example: UA-69986668-1"),

array("name"=>"网站域名",
"id"=>$sn."_ggtjym",
"in"=>$sn."_ggtj_child",
"type"=>"text",
"std"=>"icaoye.com"),

array("name"=>"自定义统计代码",
"desc"=>"输入自定义统计代码, 会自动添加到页脚, 需包含&lt;script&gt;标签",
"id"=>$sn."_tjcode",
"type"=>"textarea"),
array("type"=>"close"),

//自定义代码
array("name"=>"自定义代码","type"=>"section"),

array("type"=>"open"),
array("name"=>"介绍",
"desc"=>"以下内容需要一定的代码知识, 您可以在这里自由的发挥, 输入任何想要分享的内容, 如站内公告、广告、友情链接等等; 或者自定义主题样式, 打造自己中意的效果; 总之, 相信您一定会利用好这里的各个模块。",
"id"=>$sn."_introduction",
"type"=>"introduction"),

array("name"=>"顶部右侧模块：",
"desc"=>"顶部右侧模块显示的内容, 该模块宽度最大宽度360px, 最小宽度240px, 高度230px, 若不知如何下手可到 <a href='http://icaoye.com/initial-header-right.html' target='_blank'>这里</a> 查看",
"id"=>$sn."_right",
"type"=>"textarea",
"std"=>""),

array("name"=>"页脚信息：",
"desc"=>"自定义页脚显示的内容",
"id"=>$sn."_footer",
"type"=>"textarea",
"std"=>""),
array("type"=>"close"),

//SMTP邮箱设置
array("name"=>"SMTP邮箱设置","type"=>"section"),

array("type"=>"open"),
array("name"=>"发件人地址：",
"id"=>$sn."_smtp_from",
"type"=>"text"),

array("name"=>"发件人昵称：",
"id"=>$sn."_smtp_fromname",
"type"=>"text"),

array("name"=>"SMTP服务器地址：",
"id"=>$sn."_smtp_host",
"type"=>"text"),

array("name"=>"SMTP端口：",
"desc"=>"SMTP邮件发送端口, 常用端口有：25、465、587, 具体联系邮件服务商",
"id"=>$sn."_smtp_port",
"type"=>"text"),

array("name"=>"SMTP加密方式：",
"desc"=>"SSL/TLS, 具体联系邮件服务商, 以免设置错误, 无法正常发送邮件",
"id"=>$sn."_smtp_secure",
"type"=>"select",
"options"=>array(" ","ssl","tls")),

array("name"=>"邮箱帐号：",
"id"=>$sn."_smtp_username",
"type"=>"text"),

array("name"=>"邮箱密码：",
"id"=>$sn."_smtp_password",
"type"=>"password"),
array("type"=>"close"),
);

function mytheme_add_admin(){
global $themename, $sn, $options;
if ( $_GET['page'] == basename(__FILE__) ){
	if ( 'save' == $_REQUEST['action'] ){
		foreach ($options as $value){
	update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
foreach ($options as $value){
	if( isset( $_REQUEST[ $value['id'] ] ) ){ update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } else{ delete_option( $value['id'] ); } }
	header("Location: admin.php?page=Initial-options.php&saved=true");
die;
}
else if( 'reset' == $_REQUEST['action'] ){
	foreach ($options as $value){
		delete_option( $value['id'] ); 
		delete_option( $value['id'].'_ck' ); }
	header("Location: admin.php?page=Initial-options.php&reset=true");
die;
}
}
add_theme_page($themename." Options", "Initial主题设置", 'edit_themes', basename(__FILE__), 'mytheme_admin');
}

function mytheme_admin(){
global $themename, $version, $sn, $options;
$soul = $themename. $version;
$i=0;
if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p>'.$themename.' 主题设置已保存</p></div>';
if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p>'.$themename.' 主题已重新设置</p></div>';

function show_category(){
	global $wpdb;
	$request = "SELECT $wpdb->terms.term_id, name FROM $wpdb->terms ";
	$request .= " LEFT JOIN $wpdb->term_taxonomy ON $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id ";
	$request .= " WHERE $wpdb->term_taxonomy.taxonomy = 'category' ";
	$request .= " ORDER BY term_id asc";
	$categorys = $wpdb->get_results($request);
	foreach ($categorys as $category){
		$output = '<span>'.$category->name.": <i>".$category->term_id.'</i></span>';
		echo $output;
	}
}
?>

<div class="wrap Initial_wrap">
<link rel="stylesheet" href="<?php bloginfo('template_url') ?>/includes/Initial-options.css"/>
<script>
jQuery(document).ready(function(){
	jQuery('.Initial_options').not(':first').hide();
	jQuery('.Initial_opts_menu li:first').addClass("current");
	jQuery('.Initial_opts_menu li').click(function(){jQuery(this).addClass("current").siblings().removeClass();jQuery(".Initial_opts_content > ul.Initial_options").eq(jQuery('.Initial_opts_menu li').index(this)).fadeIn('normal').siblings().hide();});
	jQuery('#ini_media').click(function() {jQuery('.ini_media_child').fadeToggle();});
	if (jQuery('#ini_media:checked').val() !== undefined) {jQuery('.ini_media_child').show();}
	jQuery('#ini_post').click(function() {jQuery('.ini_post_child').fadeToggle();});
	if (jQuery('#ini_post:checked').val() !== undefined) {jQuery('.ini_post_child').show();}
	jQuery('#ini_bdshare').click(function() {jQuery('.ini_bdshare_child').fadeToggle();});
	if (jQuery('#ini_bdshare:checked').val() !== undefined) {jQuery('.ini_bdshare_child').show();}
	jQuery('#ini_bdtj').click(function() {jQuery('.ini_bdtj_child').fadeToggle();});
	if (jQuery('#ini_bdtj:checked').val() !== undefined) {jQuery('.ini_bdtj_child').show();}
	jQuery('#ini_ggtj').click(function() {jQuery('.ini_ggtj_child').fadeToggle();});
	if (jQuery('#ini_ggtj:checked').val() !== undefined) {jQuery('.ini_ggtj_child').show();}
	jQuery('#ini_custom_bulletin').click(function() {jQuery('.ini_custom_bulletin_child').fadeToggle();});
	if (jQuery('#ini_custom_bulletin:checked').val() !== undefined) {jQuery('.ini_custom_bulletin_child').show();}
});
</script>
<h2><?php echo $soul;?> 设置页面</h2>
<br>
<div class="header">
<h3 style="font-weight:400">主题：<?php echo $soul;?><span style="margin-left:60px;">作者：<a href="http://icaoye.com" target="_blank">柳飘清枫</a></span></h3>
<div class="Initial_introduction">
亲, 欢迎您使用 <?php echo $soul;?> 主题, 这里是主题的设置界面, 您可以根据自己的需要设置以下项目。<br>
Display = 显示　　　Hide = 不显示<br>
<div class="category-id"><strong>以下是您小站的所有分类ID, 在下面的设置里会用到：</strong><br><?php show_category(); ?></div>
<p style="color:red;font-weight:800;margin-bottom:6px">设置出错可以点击“恢复默认”按钮, 您所有的设置将会被清空！</p>
<form method="post">
<input type="hidden" name="action" value="reset" />
<input name="reset" type="submit" value="恢复默认" class="button" title="Silence is gold！" onclick ="if(confirm('您确定要恢复到默认设置？')){return true;}else{return false;}" style=margin-right:10px>
<input name="donate" type="button" value="购买主题" class="button" title="Silence is always gold！" onclick="window.open('http://icaoye.com/initial-1-0.html')"/>
</form>
</div>
</div>
<br>
<div class="Initial_opts">
<form method="post" name="form">
<ul class="Initial_opts_menu">
<?php  foreach ($options as $value){
switch ( $value['type'] ){
case "section":
$i++;?>
<li><h3><?php echo $value['name']; ?></h3></li>
<?php break;}
};?>
<span id="save-button">
<input type="hidden" name="action" value="save" />
<input name="save" type="submit" value="保存设置" class="button"/>
</span>
</ul>
<div class="Initial_opts_content">
<?php foreach ($options as $value){
switch ( $value['type'] ){
case "open": echo'<ul class="Initial_options">'; break;
case "close": echo'</ul>'; break;
case "introduction": echo'<li class="Initial_input Initial_introduction">'.$value['desc'].'</li>'; break;
case 'text': echo'<li class="Initial_input Initial_text '.$value['in'].'"><label for="'.$value['id'].'">'.$value['name'].'</label><input name="'.$value['id'].'" type="text" value="';if ( get_settings($value['id'])!=""){ echo stripslashes(get_settings( $value['id']) );} else { echo $value['std'];} echo'" /><small>'.$value['desc'].'</small></li>'; break;
case 'password': echo'<li class="Initial_input Initial_password '.$value['in'].'"><label for="'.$value['id'].'">'.$value['name'].'</label><input name="'.$value['id'].'" type="password" value="';if (get_settings($value['id'])!= ""){ echo stripslashes(get_settings( $value['id']));} else { echo $value['std'];} echo'" /><small>'.$value['desc'].'</small></li>'; break;
case 'textarea': echo'<li class="Initial_input Initial_textarea '.$value['in'].'"><label for="'.$value['id'].'">'.$value['name'].'</label><small>'.$value['desc'].'</small><textarea name="'.$value['id'].'" type="textarea" cols="" rows="" onclick="if(this.value == \''.$value['std'].'\'){this.value = \'\';}" onblur="if(this.value == \'\'){this.value = \''.$value['std'].'\';}">';if (get_settings($value['id'])!=""){ echo stripslashes(get_settings( $value['id']));} else { echo $value['std'];} echo'</textarea></li>'; break;
case 'select': echo'<li class="Initial_input Initial_select '.$value['in'].'"><label for="'.$value['id'].'">'.$value['name'].'</label><select name="'.$value['id'].'">';foreach ($value['options'] as $option){ echo'<option value="'.$option.'"';if (get_settings( $value['id'])==$option){ echo 'selected="selected"';} echo'>';if ((empty($option) || $option == '' ) && isset($value['default'])){ echo $value['default'];} else { echo $option;} echo'</option>';} echo'</select><small>'.$value['desc'].'</small></li>'; break;
case "checkbox": echo'<li class="Initial_input Initial_checkbox"><label for="'.$value['id'].'">'.$value['name'].'</label>';if(!get_option($value['id']) && !get_option($value['id'].'_ck')){if($value['std']=='true'){ add_option($value['id'],'true'); add_option($value['id'].'_ck','true');}}if(get_option($value['id'])){ $checked = "checked=\"checked\"";} else {$checked = "";} echo'<input type="checkbox" name="'.$value['id'].'" id="'.$value['id'].'" value="true" '.$checked.' /><small>'.$value['desc'].'</small></li>'; break;
}
}
?>
</div>
</form>
</ul>
</div>
<?php };add_action('admin_menu', 'mytheme_add_admin');?>